package at.fhj.itm11.fotorater.service;

import java.util.logging.Logger;

import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.persistence.EntityManager;

import at.fhj.itm11.fotorater.data.CategoryRepository;
import at.fhj.itm11.fotorater.model.Category;
import at.fhj.itm11.fotorater.model.Photo;

@Stateless
public class PhotoUploadService {
	@Inject
	private Logger log;

	@Inject
	CategoryRepository catRepo;

	@Inject
	private EntityManager em;

	public void upload(String name, String filePath, String category) {
		Photo p = new Photo();
		p.setName(name);
		p.setFilepath(filePath);
		Category cat = catRepo.findByName(category);
		p.setCategory(cat);
		em.persist(p);
		log.info("Photo " + name + " (" + category + ") has been uploaded to "
				+ filePath);

	}
}
